package sunwul.mall.business.manager.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sunwul.mall.business.manager.entity.SysMenu;
import sunwul.mall.business.manager.service.SysMenuService;
import sunwul.mall.business.manager.vo.MenuAndAuth;
import sunwul.mall.commonbase.model.Result;
import sunwul.mall.commoncore.util.AuthUtils;

import java.util.Set;

/**
 * 菜单管理服务控制器
 *
 * @author sunwul
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2024-12-30 15:19:01
 */
@Slf4j
@Api(tags = "系统权限管理")
@RestController
@RequestMapping("/sys/menu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @ApiOperation("查询用户的菜单权限和操作权限")
    @GetMapping("nav")
    public Result<MenuAndAuth> loadUserMenuAndAuth() {
        log.info("/sys/menu/nav");
        // 查询当前登录用户操作权限集合
        Set<String> perms = AuthUtils.getLoginUserPerms();
        // 获取当前登录用户标识
        Long userId = AuthUtils.getLoginUserId();
        // 根据用户标识查询菜单权限集合
        Set<SysMenu> sysMenus = sysMenuService.queryUserMenuListByUserId(userId);

        MenuAndAuth menuAndAuth = new MenuAndAuth(sysMenus, perms);
        return Result.success(menuAndAuth);
    }

}